#define  _TPMS_MSG_GLOBAL_
#include "config.h"

void ClearCarTiresLinktatus(void)
{
	TPMSMsgInfo.CarTireS[0].t_Linking=0xff;
	TPMSMsgInfo.CarTireS[1].t_Linking=0xff;
	TPMSMsgInfo.CarTireS[2].t_Linking=0xff;
	TPMSMsgInfo.CarTireS[3].t_Linking=0xff;
}

void dealTPMSAlarmMsg(U8 whichTire)
{
	 if(TPMSMsgInfo.CarTireS[whichTire].t_Temperature > TPMSMsgInfo.CarTireS[0].t_T_high_value)
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_high_temp = 1;	 
	 }
	 else
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_high_temp = 0;			 
	 }
	
	 if(TPMSMsgInfo.CarTireS[whichTire].t_Pressure == 0xFF)
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_high_p = 0;		 
		 TPMSMsgInfo.CarTireS[whichTire].t_low_p = 0;
		 TPMSMsgInfo.CarTireS[whichTire].t_high_temp = 0;		 
	 }
	 else if(TPMSMsgInfo.CarTireS[whichTire].t_Pressure > TPMSMsgInfo.CarTireS[0].t_p_high_value)
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_high_p = 1;	 
	 }
	 else if(TPMSMsgInfo.CarTireS[whichTire].t_Pressure < TPMSMsgInfo.CarTireS[0].t_p_low_value)
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_low_p = 1;	 
	 }	 
	 else
	 {
		 TPMSMsgInfo.CarTireS[whichTire].t_high_p = 0;		 
		 TPMSMsgInfo.CarTireS[whichTire].t_low_p = 0;				 
	 }
	 
  TPMSMsgInfo.CarTireS[whichTire].alarm = 0x38 & ((TPMSMsgInfo.CarTireS[whichTire].t_high_temp<<3) | (TPMSMsgInfo.CarTireS[whichTire].t_high_p<<4) | (TPMSMsgInfo.CarTireS[whichTire].t_low_p<<5));

}

void TPMSFreeIdleProc(void)
{
	
#if 0
		transTPMSAlarmProc();
		
		if(ePageTPMSPairing == CANMsgInfo.ePageTPMS)
		{
			if(transToUITPMSInfo.selectWhichPre != transToUITPMSInfo.selectWhich)
			{
				transToUITPMSInfo.selectWhichPre = transToUITPMSInfo.selectWhich;
				SendLinkCmd(transToUITPMSInfo.selectWhich);		
				TPMSMsgInfo.CarTireS[0].t_Linking=0xff;
				TPMSMsgInfo.CarTireS[1].t_Linking=0xff;
				TPMSMsgInfo.CarTireS[2].t_Linking=0xff;
				TPMSMsgInfo.CarTireS[3].t_Linking=0xff;
				TPMSMsgInfo.CarTireS[transToUITPMSInfo.selectWhich].t_Linking=0;	
				carTirePairingEnble(transToUITPMSInfo.selectWhich);			
				transTPMSPageDeal(transToUITPMSInfo.selectWhich);		
			}
		} 	
		
		if(TPMSMsgInfo.CarTireS[0].alarm ||TPMSMsgInfo.CarTireS[1].alarm||TPMSMsgInfo.CarTireS[2].alarm||TPMSMsgInfo.CarTireS[3].alarm)//????
		{
			if(TPMSMsgInfo.clearTireAlarm)
			{
				TPMSMsgInfo.bHaveTpmsAlarm = FALSE;
				if(GetTickCount() - TPMSMsgInfo.clearTireAlarmTimer > T_1S*300)
				{
					//if(TPMSMsgInfo.clearTireAlarmCount<5)
					{
						TPMSMsgInfo.clearTireAlarmTimer = GetTickCount();
						TPMSMsgInfo.clearTireAlarmCount++;
						TPMSMsgInfo.clearTireAlarm=0;
					}		
				}
			}
			else
			{
				if(isShowTPMSEnble())//自动调到胎压页面
				{
					TPMSMsgInfo.bHaveTpmsAlarm = TRUE;
					if(ePageTPMSPairing != CANMsgInfo.ePageTPMS)
					{
						CANMsgInfo.bSteeringKey = TRUE;
						CANMsgInfo.ePageTPMS = ePageTPMSStatus;//这个屏蔽
					}
				}
			}
		}
		else
		{
			TPMSMsgInfo.clearTireAlarmCount=0;
			TPMSMsgInfo.clearTireAlarm=0;
			TPMSMsgInfo.bHaveTpmsAlarm = FALSE;
			TPMSMsgInfo.tpmsAlarmCount=0;
		}	
		#endif
}

void TPMSMsgInit(void)
{
	memset(&TPMSMsgInfo,0,sizeof(TPMS_MSG_INFO));
	TPMSMsgInfo.CarTireS[0].t_p_high_value=0x32;
	TPMSMsgInfo.CarTireS[0].t_p_low_value=0x18;
	TPMSMsgInfo.CarTireS[0].t_T_high_value=0x69;
	TPMSMsgInfo.CarTireS[0].t_Pressure = 0xff;
	TPMSMsgInfo.CarTireS[1].t_Pressure = 0xff;
	TPMSMsgInfo.CarTireS[2].t_Pressure = 0xff;
	TPMSMsgInfo.CarTireS[3].t_Pressure = 0xff;
	ClearCarTiresLinktatus();
	TPMSMsgInfo.haveExtTpms = FALSE;
	TPMSMsgInfo.lastRecPingTime = GetTickCount() + T_1S*5;

}


